// 给定一个链表: 1->2->3->4->5, 和 k = 2.

// 返回链表 4->5.

/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} k
 * @return {ListNode}
 */
var getKthFromEnd = function (head, k) {
    // 快慢指针
    let fast = head
    let slow = head
    let i = 0
    //快指针先走k步
    while (i++ < k) {
        fast = fast.next
    }
    //然后一起走，快指针到null截止，返回慢指针的位置
    while (fast) {
        fast = fast.next
        slow = slow.next
    }

    return slow

};